package com.koron.standard.gradeStock.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koron.standard.gradeStock.bean.po.GradeItem;
import com.koron.standard.gradeStock.mapper.GradeItemMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 大修分级分项验收标准-项目(GradeItem)表服务实现类
 *
 * @author jzp
 * @since 2021-09-26
 */
@Service
public class GradeItemService extends ServiceImpl<GradeItemMapper, GradeItem> {

    public List<GradeItem> listByGradeId(String gradeId) {
        LambdaQueryWrapper<GradeItem> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GradeItem::getGradeId, gradeId);
        return list(wrapper);
    }

    public List<GradeItem> listByGradeIds(List<String> gradeIds) {
        LambdaQueryWrapper<GradeItem> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(GradeItem::getGradeId, gradeIds);
        return list(wrapper);
    }

    public void removeByGradeId(String gradeId) {
        if (StrUtil.isEmpty(gradeId)) {
            return;
        }
        LambdaQueryWrapper<GradeItem> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GradeItem::getGradeId, gradeId);
        List<GradeItem> list = list(wrapper);
        removeByIds(list.stream().map(GradeItem::getId).collect(Collectors.toList()));
    }
}
